import Vue from 'vue'
import Router from 'vue-router'
import {
  RECHARGE_BY_OTHER,
  WELFARE,
  APP_GIFT,
  RECHARGE_BY_APP_WECHART,
  RECHARGE_BY_APP_ALI,
  RECHARGE_BY_JS_WECHART,
  RECHARGE_BY_UNION_WAP,
  RECHARGE_BY_CHENGTAI,
  RECHARGE_BY_BWT_UNION,
  PAY_ONLINE,
  PAY_OFFLINE,
  PAY_BUS,
  PAY_STAFF_MEAL,
  REFUND_BUS,
  REFUND_OFFLINE,
  REFUND_STAFF_MEAL,
  REFUND_ONLINE,
  REFUND_TRANSFER,
  RETURN_CASH_CARD_DESTROY,
  RETURN_CASH_APP_CHARGE,
  FREEZON_MEAL,
  UNFREEZON_MEAL
} from '../constants/TradeDetailType.js'
const AppRechargeConsumeDetail = () =>
  import('../page/AppRechargeConsumeDetail.vue')
const BenifitRechargeConsumeDetail = () =>
  import('../page/BenifitRechargeConsumeDetail.vue')
const BusConsumeDetail = () => import('../page/BusConsumeDetail.vue')
const CashConsumeDetail = () => import('../page/CashConsumeDetail.vue')
const MealConsumeDetail = () => import('../page/MealConsumeDetail.vue')
const OfflineConsumeDetail = () => import('../page/OfflineConsumeDetail.vue')
const OnlineConsumeDetail = () => import('../page/OnlineConsumeDetail.vue')
const RefundConsumeDetail = () => import('../page/RefundConsumeDetail.vue')

Vue.use(Router)

const router = new Router({
  routes: [
    {
      // 默认的页面,用户开发调试时更改
      path: '/',
      redirect: '/appRechargeConsumeDetail'
    },
    {
      path: '/appRechargeConsumeDetail',
      component: AppRechargeConsumeDetail,
      name: 'appRechargeConsumeDetail'
    },
    {
      path: '/benifitRechargeConsumeDetail',
      component: BenifitRechargeConsumeDetail,
      name: 'benifitRechargeConsumeDetail'
    },
    {
      path: '/busConsumeDetail',
      component: BusConsumeDetail,
      name: 'busConsumeDetail'
    },
    {
      path: '/cashConsumeDetail',
      component: CashConsumeDetail,
      name: 'cashConsumeDetail'
    },
    {
      path: '/mealConsumeDetail',
      component: MealConsumeDetail,
      name: 'mealConsumeDetail'
    },
    {
      path: '/offlineConsumeDetail',
      component: OfflineConsumeDetail,
      name: 'offlineConsumeDetail'
    },
    {
      path: '/onlineConsumeDetail',
      component: OnlineConsumeDetail,
      name: 'onlineConsumeDetail'
    },
    {
      path: '/refundConsumeDetail',
      component: RefundConsumeDetail,
      name: 'refundConsumeDetail'
    }
  ]
})

// 全局路由守护
router.beforeEach((to, from, next) => {
  // 根据url上带入的账单小类型,指向不同的路由
  let state = parseInt(to.query.state)
  let path
  switch (state) {
    case APP_GIFT:
    case WELFARE:
      path = '/benifitRechargeConsumeDetail'
      break

    case RECHARGE_BY_APP_ALI:
    case RECHARGE_BY_APP_WECHART:
    case RECHARGE_BY_OTHER:
    case RECHARGE_BY_JS_WECHART:
    case RECHARGE_BY_UNION_WAP:
    case RECHARGE_BY_CHENGTAI:
    case RECHARGE_BY_BWT_UNION:
      path = '/appRechargeConsumeDetail'
      break

    case PAY_BUS:
      path = '/busConsumeDetail'
      break

    case PAY_OFFLINE:
      path = '/offlineConsumeDetail'
      break

    case PAY_ONLINE:
      path = '/onlineConsumeDetail'
      break

    case PAY_STAFF_MEAL:
    case FREEZON_MEAL:
    case UNFREEZON_MEAL:
      path = '/mealConsumeDetail'
      break

    case REFUND_BUS:
    case REFUND_OFFLINE:
    case REFUND_STAFF_MEAL:
    case REFUND_ONLINE:
    case REFUND_TRANSFER:
      path = '/refundConsumeDetail'
      break

    case RETURN_CASH_APP_CHARGE:
    case RETURN_CASH_CARD_DESTROY:
      path = 'cashConsumeDetail'
      break

    default:
      break
  }
  console.log(state)
  if (path) next({ path: path })
  next()
})

export default router
